/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 08-ene-2011, 18:44:34
 */
package interfaz;

import java.util.concurrent.Semaphore;
import javax.swing.ImageIcon;

/**
 *
 * @author joshi
 */
import javax.swing.JOptionPane;
import logica.general;
import logica.principal;

public class Principal extends javax.swing.JFrame implements Runnable {

    /** Creates new form Principal */
    /**
     * @set maximize
     */
    static principal prin;
    int tiempo;
    String salida;
    double x=0, y=0;
    static int count=0;
    boolean pause = false;
    boolean stop = false, nuevo=false;
    int reloj = 0;
    private boolean empezar;
    public Principal(principal prin, int tiempo) {
        initComponents();
        this.prin = prin;
        this.tiempo = tiempo;
        logica.general.velocidad = 1000;
        salida = "";
        
        this.setExtendedState(MAXIMIZED_BOTH);
        logica.general.exc_mut_cola=new Semaphore(1,true);
        this.setIconImage(new ImageIcon(getClass().getResource("/images/face-monkey.png")).getImage());
        prin.setPanel(panel_entrada);
        prin.setPanel2(jPanel3);
        prin.setPanel3(jPanel2);
        prin.setPanel4(jPanel4);
        general.pausa=false;
     
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        jToggleButton4 = new javax.swing.JToggleButton();
        jButton3 = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        jpausa = new javax.swing.JButton();
        jplay = new javax.swing.JToggleButton();
        jstop = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jToggleButton1 = new javax.swing.JToggleButton();
        jToggleButton2 = new javax.swing.JToggleButton();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        jToggleButton5 = new javax.swing.JToggleButton();
        jToolBar2 = new javax.swing.JToolBar();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        panel_entrada = new javax.swing.JPanel();
        jSeparator6 = new javax.swing.JSeparator();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jSeparator8 = new javax.swing.JSeparator();
        jPanel2 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jSeparator7 = new javax.swing.JSeparator();
        jLabel8 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        jMenuItem2 = new javax.swing.JMenuItem();
        Editar = new javax.swing.JMenu();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem8 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Simulador");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jToolBar1.setRollover(true);

        jToggleButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/document-new.png"))); // NOI18N
        jToggleButton4.setFocusable(false);
        jToggleButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jToggleButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToggleButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton4ActionPerformed(evt);
            }
        });
        jToolBar1.add(jToggleButton4);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/document-properties.png"))); // NOI18N
        jButton3.setEnabled(false);
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton3);
        jToolBar1.add(jSeparator4);

        jpausa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Gnome-Media-Playback-Pause-48.png"))); // NOI18N
        jpausa.setEnabled(false);
        jpausa.setFocusable(false);
        jpausa.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jpausa.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jpausa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jpausaActionPerformed(evt);
            }
        });
        jToolBar1.add(jpausa);

        jplay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Gnome-Media-Playback-Start-48.png"))); // NOI18N
        jplay.setFocusable(false);
        jplay.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jplay.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jplay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jplayActionPerformed(evt);
            }
        });
        jToolBar1.add(jplay);

        jstop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Gnome-Media-Playback-Stop-48.png"))); // NOI18N
        jstop.setEnabled(false);
        jstop.setFocusable(false);
        jstop.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jstop.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jstop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jstopActionPerformed(evt);
            }
        });
        jToolBar1.add(jstop);
        jToolBar1.add(jSeparator1);

        jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/media-seek-backward.png"))); // NOI18N
        jToggleButton1.setFocusable(false);
        jToggleButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jToggleButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jToggleButton1);

        jToggleButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/media-seek-forward.png"))); // NOI18N
        jToggleButton2.setFocusable(false);
        jToggleButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jToggleButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jToggleButton2);
        jToolBar1.add(jSeparator5);

        jToggleButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/utilities-system-monitor.png"))); // NOI18N
        jToggleButton5.setFocusable(false);
        jToggleButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jToggleButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToggleButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton5ActionPerformed(evt);
            }
        });
        jToolBar1.add(jToggleButton5);

        jToolBar2.setRollover(true);

        jLabel1.setText("Tiempo de simulacion:");
        jToolBar2.add(jLabel1);

        jLabel2.setFont(new java.awt.Font("DejaVu Sans", 1, 15));
        jLabel2.setText("0");
        jToolBar2.add(jLabel2);

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/system-log-out.png"))); // NOI18N

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/fifo.png"))); // NOI18N
        jLabel4.setText("Cola");

        panel_entrada.setLayout(null);
        panel_entrada.add(jSeparator6);
        jSeparator6.setBounds(20, 20, 130, 10);

        jLabel6.setText("0");

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/application-exit.png"))); // NOI18N
        jLabel7.setText("Salida");

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Servidores"));
        jScrollPane1.setViewportView(jPanel3);

        jPanel4.setLayout(null);

        jLabel9.setText("|");
        jPanel4.add(jLabel9);
        jLabel9.setBounds(40, 100, 10, 14);
        jPanel4.add(jLabel10);
        jLabel10.setBounds(40, 0, 10, 0);
        jPanel4.add(jLabel11);
        jLabel11.setBounds(40, 20, 10, 0);
        jPanel4.add(jLabel13);
        jLabel13.setBounds(40, 40, 10, 0);
        jPanel4.add(jLabel14);
        jLabel14.setBounds(40, 60, 10, 0);

        jLabel15.setText("|");
        jPanel4.add(jLabel15);
        jLabel15.setBounds(40, 80, 10, 14);

        jSeparator8.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel4.add(jSeparator8);
        jSeparator8.setBounds(30, -10, 10, 120);

        jPanel2.setLayout(null);
        jPanel2.add(jLabel12);
        jLabel12.setBounds(0, 40, 190, 10);
        jPanel2.add(jSeparator7);
        jSeparator7.setBounds(0, 20, 190, 2);

        jLabel8.setText("0");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3)
                        .addGap(6, 6, 6)
                        .addComponent(panel_entrada, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 707, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel7)
                                        .addGap(48, 48, 48))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel8)
                                        .addGap(98, 98, 98))))
                            .addComponent(jLabel4)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(256, 256, 256)
                        .addComponent(jLabel6)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(258, 258, 258)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(79, 79, 79)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(panel_entrada, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel3)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(212, Short.MAX_VALUE))
        );

        jMenu1.setText("Archivo");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/new32.png"))); // NOI18N
        jMenuItem1.setText("Nuevo");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);
        jMenu1.add(jSeparator2);

        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/application-exit (1).png"))); // NOI18N
        jMenuItem2.setText("Salir");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        Editar.setText("Editar");

        jMenuItem9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/document-properties (1).png"))); // NOI18N
        jMenuItem9.setText("Propiedades");
        Editar.add(jMenuItem9);

        jMenuBar1.add(Editar);

        jMenu3.setText("Run");
        jMenu3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu3ActionPerformed(evt);
            }
        });

        jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/media-playback-start.png"))); // NOI18N
        jMenuItem3.setText("Start");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem3);

        jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/media-playback-stop.png"))); // NOI18N
        jMenuItem4.setText("Stop");
        jMenu3.add(jMenuItem4);

        jMenuItem5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/media-playback-pause.png"))); // NOI18N
        jMenuItem5.setText("Pause");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem5);
        jMenu3.add(jSeparator3);

        jMenuItem6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/media-seek-forward (1).png"))); // NOI18N
        jMenuItem6.setText("Speed +");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem6);

        jMenuItem7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/media-seek-backward (1).png"))); // NOI18N
        jMenuItem7.setText("Speed -");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem7);

        jMenuBar1.add(jMenu3);

        jMenu4.setText("Ver");

        jMenuItem10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/utilities-system-monitor (1).png"))); // NOI18N
        jMenuItem10.setText("Resultados");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem10);

        jMenuBar1.add(jMenu4);

        jMenu2.setText("Ayuda");

        jMenuItem8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/help-faq.png"))); // NOI18N
        jMenuItem8.setText("Acerca de ");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem8);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 1287, Short.MAX_VALUE)
            .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 1287, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenu1ActionPerformed

    private void jMenu3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu3ActionPerformed
        // TODO add your handling code here:
        stop();
    }//GEN-LAST:event_jMenu3ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        salir();
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jplayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jplayActionPerformed
        play();
    }//GEN-LAST:event_jplayActionPerformed

    private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton2ActionPerformed
        // TODO add your handling code here:
       fast();
    }//GEN-LAST:event_jToggleButton2ActionPerformed

    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
        // TODO add your handling code here:
      slow();
    }//GEN-LAST:event_jToggleButton1ActionPerformed

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        // TODO add your handling code here:
        about ab= new about();
        ab.setVisible(true);
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed
        // TODO add your handling code here:
        show_resultados();
    }//GEN-LAST:event_jMenuItem10ActionPerformed

    private void jToggleButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton5ActionPerformed
        // TODO add your handling code here:
        show_resultados();
    }//GEN-LAST:event_jToggleButton5ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // TODO add your handling code here:
        play();
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jpausaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jpausaActionPerformed
        // TODO add your handling code here:
        pause();
    }//GEN-LAST:event_jpausaActionPerformed

    private void jstopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jstopActionPerformed
        // TODO add your handling code here:
        stop();
    }//GEN-LAST:event_jstopActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        // TODO add your handling code here:
        fast();
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        // TODO add your handling code here:
        slow();
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        ver_datos();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        // TODO add your handling code here:
        pause();
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        nuevo();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jToggleButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton4ActionPerformed
        // TODO add your handling code here:
        nuevo();
    }//GEN-LAST:event_jToggleButton4ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        if (nuevo){
            
        }
    }//GEN-LAST:event_formWindowClosing
    public static void incCola(){
        try{
            logica.general.exc_mut_cola.acquire();
           // int cola=Integer.parseInt(jLabel6.getText());
         //   cola++;
            jLabel6.setText(Integer.toString(prin.cola.size()));
            logica.general.exc_mut_cola.release();
        }catch(Exception ev){
            
        }
        
    }
    public static void slCola(){
        try{
            logica.general.exc_mut_cola.acquire();
           // int cola=Integer.parseInt(jLabel6.getText());
         //   cola++;
            jLabel6.setText(Integer.toString(prin.cola.size()));
            logica.general.exc_mut_cola.release();
        }catch(Exception ev){
            
        }
    }

    public static void count_sale(){
        count++;
        //jLabel8.setVisible(false);
        jLabel8.setText(count+"");
    }


    public void run() {
        x=0; y=0;
        int z = 0;
        try {
            for (int i = 0; i < tiempo; i++) {
                  jLabel2.setText(Integer.toString(i));
                Thread.sleep(logica.general.velocidad);
                while(logica.general.pausa){
                    Thread.sleep(100);
                }
            }
            prin.matar();

            for (int i = 0; i < logica.general.todos.size(); i++) {
                x += logica.general.todos.get(i).getTiempoSistema();
                y += (logica.general.todos.get(i).getTiempoSistema() - logica.general.todos.get(i).getTiempoServicio());
            }
            for (int i = 0; i < prin.getServidores().size(); i++) {
                if (prin.getServidores().get(i).getAtendida() != null) {
                    z++;
                }
            }

            show_resultados();

//            salida = "Personas atendidas:" + Integer.toString(logica.general.todos.size()) + "\n";
//            salida += "tiempo promedio de espera  en el sistema:" + Double.toString(x / logica.general.todos.size()) + "\n";
//            salida += "tiempo promedio de espera en la cola:" + Double.toString(y / logica.general.todos.size()) + "\n";
//            salida += "longitud de la cola:" + Integer.toString(prin.getCola().size()) + "\n";
//            salida += "personas en el sistema:" + Integer.toString(prin.getCola().size() + z);
//            javax.swing.JOptionPane.showMessageDialog(null,salida,"",javax.swing.JOptionPane.INFORMATION_MESSAGE);
            jpausa.setEnabled(true);

        } catch (Exception ev) {
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu Editar;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    public static javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    public static javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JSeparator jSeparator8;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToggleButton jToggleButton2;
    private javax.swing.JToggleButton jToggleButton4;
    private javax.swing.JToggleButton jToggleButton5;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JButton jpausa;
    private javax.swing.JToggleButton jplay;
    private javax.swing.JButton jstop;
    private javax.swing.JPanel panel_entrada;
    // End of variables declaration//GEN-END:variables

    private void show_resultados() {
        resultados res = new resultados(Integer.toString(logica.general.todos.size()),
                    Double.toString(x / logica.general.todos.size()),Double.toString(y / logica.general.todos.size()),
                    Integer.toString(prin.getCola().size()),Integer.toString(prin.getCola().size()));
            res.setVisible(true);
    }

    private void play() {
        if (stop){
            stop = false;
        }else if(empezar){
            general.pausa=false;
            jplay.setEnabled(false);
            jpausa.setEnabled(true);
            jstop.setEnabled(true);
        }
        else{
        Thread hilo = new Thread(this);
        prin.inicializarProcesos();
        hilo.start();
        jplay.setEnabled(false);
        jpausa.setEnabled(true);
        jstop.setEnabled(true);
        empezar=true;
        }
    }

    private void slow() {
        if(logica.general.velocidad<100&&logica.general.velocidad>10){
            logica.general.velocidad+=10;
        }
        else if(logica.general.velocidad>100){
            logica.general.velocidad+=100;
        }
    }

    private void fast() {
       if(logica.general.velocidad<=100&&logica.general.velocidad>10){
            logica.general.velocidad-=10;
        }
        else if(logica.general.velocidad>100){
            logica.general.velocidad-=100;
        }
    }

    private void salir() {
        int confirmado = JOptionPane.showConfirmDialog(null, "¿Está seguro que desea salir de la aplicación?");
        if (JOptionPane.OK_OPTION == confirmado){
            System.exit(0);
        }
        
    }

    private void pause() {
        this.pause = true;
       /* reloj = logica.general.velocidad;
        logica.general.velocidad = 1000000000;*/
        general.pausa=true;
        this.jpausa.setEnabled(false);
        this.jplay.setEnabled(true);
       // jplay.
    }

    private void stop() {
        this.stop = true;
        logica.general.velocidad = 1000000000;
        this.jstop.setEnabled(false);
        this.jplay.setEnabled(true);
    }

    private void ver_datos() {

    }

    private void nuevo() {
        int confirmado = JOptionPane.showConfirmDialog(null, "¿Al crear una nueva animcación se perderan todos los datos no guardados?");
        if (JOptionPane.OK_OPTION == confirmado){
            nuevo = true;
            propiedades p = new propiedades();
            p.setVisible(true);
            this.setVisible(false);
         
        }
    }
}
